import 'package:share_fit/app/models/base_model.dart';
import 'package:share_fit/app/tools/log_utils.dart';

class ExerciseDataSummary extends BaseModel {
  int calorieSum = 0;
  int distanceSum = 0;
  int durationSum = 0;

  int durationTarget = 0;
  int calorieTarget = 0;
  int distanceTarget = 0;

  get getDistanceProcessValue {
    return ((distanceTarget - distanceSum) / 100 / 100).toDouble();
  }

  get getCalorieProcessValue {
    return ((calorieTarget - calorieSum) / 100 / 100).toDouble();
  }

  get getDurationProcessValue {
    return ((durationTarget - durationSum) / 100 / 100).toDouble();
  }

  @override
  bool from(Map<dynamic, dynamic> map) {
    try {
      calorieSum = map['calorieSum'] ?? 0;
      List motionDetailList = map['motionDetailList'] ?? [];

      if (motionDetailList.isNotEmpty) {
        durationSum = motionDetailList.map((e) => e['distance']).reduce((value, element) => value + element['distance']);
      }
    } catch(e, stack) {
      logger.d(e);
    }
    return true;
  }

  @override
  // TODO: implement props
  List<Object?> get props => throw UnimplementedError();

}